package com.example.q_kang.hhh.main;

import com.hjq.toast.ToastUtils;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import com.sskj.base.BasePresenter;
import com.sskj.base.api.Constant;
import com.sskj.base.base.HttpData;
import com.sskj.base.bean.NoticeBean;
import com.sskj.base.bean.OrderCommmonBean;
import com.sskj.base.bean.UpdataBean;
import com.sskj.base.bean.UserData;
import com.example.q_kang.hhh.api.JsonCallBack;

public class MainPresenter extends BasePresenter<MainActivity> {

    public void getUserData() {
        httpService.getUserData()
                .tag(this)
                .execute(new JsonCallBack<HttpData<UserData>>() {
                    @Override
                    public void onSuccess(Response<HttpData<UserData>> response) {
                        HttpData<UserData> httpData = response.body();
                        if (httpData.getStatus() == Constant.OK) {
                            if (httpData.getData().getUserinfo() != null) {
                                mView.getUserSuccess(httpData.getData().getUserinfo());
                            }
                        }
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                        mView.hideLoading();
                    }
                });
    }

    public void updata(String verName) {
        httpService.updata(verName)
                .execute(new JsonCallBack<HttpData<UpdataBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<UpdataBean>> response) {
                        HttpData<UpdataBean> body = response.body();
                        if (body.getStatus() == Constant.OK) {
                            mView.needUpdata(body.getData());
                        }
                    }
                });

    }

    public void getOrderCommonData() {
        httpService.getOrderCommmonData()
                .tag(this)
                .execute(new JsonCallBack<HttpData<OrderCommmonBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<OrderCommmonBean>> response) {
                        HttpData<OrderCommmonBean> body = response.body();
                        if (body.getStatus() == Constant.OK) {
                            mView.getOrderDataSucess(body.getData());
                        }
                    }
                });
    }

    public void getNotice() {
        httpService.getNotice()
                .execute(new JsonCallBack<HttpData<NoticeBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<NoticeBean>> response) {
                        HttpData body = response.body();
                        if (body.getStatus() == Constant.OK) {
                            mView.showNoticeDialog((NoticeBean) body.getData());
                        }
                    }
                });

    }
}
